<template>
  <div class="p-d">
    <div class="b-f p-d">
      <SearchComp :searchForm="searchForm"
        :searchData="queryString"
        :searchAction="searchAction"></SearchComp>
      <div class="btnStyle flex-between p-t">
        <ButtonComp :buttonData="buttonData" />
      </div>
      <div class="m-t">
        <TableCompEle class="m-t"
          ref="multipleTable"
          height="50vh"
          :tableData="tableData"
          :tableConfig="tableConfig"
          :tableAction="tableAction"
          :isSelect="true"
          :isIndex="true"
          :isShowPage="true"
          :queryParams="queryParams"
          @getPagination="getList"
          @handleSelectionChange="handleSelectionChange"></TableCompEle>
      </div>
    </div>
    <AddComp ref="addRef"
      @close="getList" />
  </div>
</template>

<script>
import AddComp from './common/add.vue'
export default {
  components: { AddComp },
  data() {
    return {
      activeName: 'all',
      buttonData: [
        {
          kind: 'button',
          label: '新增',
          plain: false,
          size: 'small',
          type: 'primary',
          click: () => {
            this.$refs.addRef.show({
              title: '新建大单位',
              isLook: 'add'
            })
          }
        },
        {
          kind: 'button',
          label: '一键导出',
          plain: false,
          size: 'small',
          type: 'warning',
          click: () => {}
        },
        {
          kind: 'button',
          label: '一键导入',
          plain: false,
          size: 'small',
          type: 'warning',
          click: () => {}
        },
        {
          kind: 'button',
          label: '批量删除',
          plain: false,
          size: 'small',
          type: 'danger',
          click: () => {
            // if (this.multipleSelection.length == 0) {
            //   this.$message({
            //     type: 'warning',
            //     message: '请选择要删除的数据'
            //   })
            //   return
            // }
            const ids = []
            // this.multipleSelection.forEach(items => {
            //   ids.push(items.id)
            // })
            this.deleteFun(ids)
          }
        }
      ],
      queryParams: {
        total: 0,
        currentPage: 1,
        pageSize: 10
      },
      tableData: [
        {
          order: '1',
          isHandle: true,
          unit: '中国人民解放军东部战区总医院',
          department: '科研管理部门',
          name: '陈冠宇',
          workPhone: '010-8927893',
          phone: '13726536872'
        },
        {
          order: '2',
          isHandle: true,
          unit: '南部战区科研机构',
          department: '后勤保障部门',
          name: '孙文博',
          workPhone: '010-3657823',
          phone: '17823437634'
        },
        {
          order: '3',
          isHandle: true,
          unit: '中部战区总医院',
          department: '医务部',
          name: '王思宇',
          workPhone: '010-7834532',
          phone: '13212382198'
        },
        {
          order: '4',
          isHandle: true,
          unit: '空军后勤部',
          department: '机场管理与维护',
          name: '张晨曦',
          workPhone: '010-6742398',
          phone: '17923428726'
        },
        {
          order: '5',
          isHandle: true,
          unit: '火箭军总医院',
          department: '质谱检测中心',
          name: '吴佳怡',
          workPhone: '010-9083453',
          phone: '17534573948'
        },
        {
          order: '6',
          isHandle: true,
          unit: '战略支援部队',
          department: '航天与导航部门',
          name: '陈冠宇',
          workPhone: '010-3542839',
          phone: '13323465434'
        },
        {
          order: '7',
          isHandle: true,
          unit: '联勤保障部队',
          department: '通信保障部门',
          name: '杨光达',
          workPhone: '010-789374',
          phone: '1576238291'
        },
        {
          order: '8',
          isHandle: true,
          unit: '解放军总后勤部',
          department: '卫生部',
          name: '张志伟',
          workPhone: '010-6982389',
          phone: '15998722763'
        },
        {
          order: '9',
          isHandle: true,
          unit: '军事科学院',
          department: '科研管理与规划部门',
          name: '陈洁',
          workPhone: '010-9802321',
          phone: '18762732919'
        },
        {
          order: '10',
          isHandle: true,
          unit: '国防大学',
          department: '科研管理部门',
          name: '刘浩',
          workPhone: '010-7992387',
          phone: '18438292834'
        }
      ],
      tableConfig: [
        {
          prop: 'order',
          label: '排序',
          isEdit: true,
          isHandle: true,
          width: 100,
          showTooltip: () => {
            return false
          },
          isType: 'Input',
          method: () => {
            this.tableData = this.tableData.sort(
              (a, b) => Number(a.order) - Number(b.order)
            )
          }
        },
        {
          prop: 'unit',
          label: '大单位名称'
        },
        {
          prop: 'department',
          label: '职能部门名称'
        },
        {
          prop: 'name',
          label: '联系人姓名',
          width: 130
        },
        {
          prop: 'workPhone',
          label: '办公电话',
          width: 140
        },
        {
          prop: 'phone',
          label: '移动电话',
          width: 140
        }
      ],
      tableAction: {
        align: () => 'center',
        width: () => String(170),
        operations: [
          {
            label: '查看',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addRef.show({
                title: '查看大单位',
                isLook: 'look',
                data: row
              })
            }
          },
          {
            label: '修改',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addRef.show({
                title: '修改大单位',
                isLook: 'edit',
                data: row
              })
            }
          },
          {
            label: '删除',
            isLink: true,
            type: 'danger',
            method: row => {
              this.deleteFun([row.id])
            }
          }
        ]
      },
      queryString: {
        title: '',
        id: ''
      },
      searchForm: {
        changeMethod: () => {
          this.queryParams.currentPage = 1
          this.getList()
        },
        formData: [
          {
            type: 'Input',
            label: '大单位名称',
            prop: 'title',
            clearable: true,
            icon: 'el-icon-search',
            placeholder: '请输入'
          },
          {
            type: 'Input',
            label: '职能部门名称',
            prop: 'title',
            clearable: true,
            icon: 'el-icon-search',
            placeholder: '请输入'
          }
        ]
      },
      searchAction: [
        {
          label: '查询',
          type: 'primary',
          handle: () => {
            this.queryParams.currentPage = 1
            this.$refs.multipleTable.clearSelection()
            this.getList()
          }
        },
        {
          label: '重置',
          type: 'primary',
          plain: true,
          handle: () => {
            this.queryString = {
              title: '',
              id: ''
            }
            this.queryParams.currentPage = 1
            this.getList()
          }
        }
      ]
    }
  },
  methods: {
    getList() {},
    deleteFun(ids) {
      console.log(
        '%c [ ids ]-216',
        'font-size:13px; background:pink; color:#bf2c9f;',
        ids
      )
      this.$confirm(`确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '删除成功'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    }
  }
}
</script>

<style lang="less" scoped>
</style>